﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FacadeSingTowerMall;
using System.Web.Security;
using DTOSingTowerMall;

namespace WebFormSingTowerMall
{
    public partial class EventsBookHistory : TransactionBaseController
    {
        OrganiserEventsBookingsFacade fOrgEventsBookings = new OrganiserEventsBookingsFacade();
        MembershipUser CurrentUser;

        protected override void Page_Load(object sender, EventArgs e)
        {
            base.Page_Load(sender, e);
            currentPage = "EventsBookHistory.aspx";
            CurrentUser = Membership.GetUser(HttpContext.Current.User.Identity.Name);
            if (!IsPostBack)
            {
                CommandField selectColumn = new CommandField();
                selectColumn.ShowSelectButton = true;


                EventBookingGridView.DataSource = fOrgEventsBookings.getOrganiserEventsBookings(CurrentUser.UserName);
                EventBookingGridView.DataBind();
                //EventBookingGridView.Columns.Add(selectColumn);
                if (EventBookingGridView.Rows.Count == 0)
                {
                    eventHistoryLbl.Text = "There are no event hall bookings made by you. To create booking go to Book Event Halls Link";
                    selectPaymentBtn.Visible = false;
                } else {
                    eventHistoryLbl.Text = "List of your Event Hall Bookings";
                    selectPaymentBtn.Visible = true;                    
                }


            }
        }

        protected void selectPaymentBtn_Click1(object sender, EventArgs e)
        {
            string str = EventBookingGridView.SelectedRow.Cells[8].Text;
            if (EventBookingGridView.SelectedRow == null) {
                string script = "alert('Please select approved Booking only');";
                ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", script, true);

            }
            else if (EventBookingGridView.SelectedRow.Cells[8].Text != "Approved")
            {
                string script = "alert('Please select Approved booking only for Payement');";
                ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", script, true);

            } else {
                try {
                    paymentDetails.bookingId = Convert.ToInt32(EventBookingGridView.SelectedRow.Cells[1].Text);
                    paymentDetails.paymentamount = Convert.ToDecimal(EventBookingGridView.SelectedRow.Cells[7].Text);
                    NextPage();
                } catch {
                    throw new Exception("either booking iD is null or Totoal price is null");
                    return;
                }
            }


        }

        //protected void EventBookingGridView_SelectedIndexChanged(object sender, EventArgs e)
        //{
            
        //}
    }
}